﻿YAHOO.example.init = function () {
    function onButtonClick(p_oEvent) {
        switch (this.get("id")) {
            case "btnSave":
                Save();
                break;
            case "btnQdnx":
                Save();
                break;
            case "btnClose":
                Close();
                break;
            case "btnNew1":
                handleAdd();
                break;
            case "btnDelete1":
                handleDelete();
                break;
            default:
                break;
        }
    }
    YAHOO.util.Event.onContentReady("toolbar", function () {
        btnSave = new YAHOO.widget.Button("btnSave");
        btnSave.on("click", onButtonClick);
        btnQdnx = new YAHOO.widget.Button("btnQdnx");
        btnQdnx.on("click", onButtonClick);
        btnClose = new YAHOO.widget.Button("btnClose");
        btnClose.on("click", onButtonClick);
    });
    YAHOO.util.Event.onContentReady("con_two_1", function () {
        btnNews1 = new YAHOO.widget.Button("btnNew1");
        btnNews1.on("click", onButtonClick);
        btnDeletes1 = new YAHOO.widget.Button("btnDelete1");
        btnDeletes1.on("click", onButtonClick);
        if (flag == 1 && strBack != "unDone") {
            btnNews1._button.style.display = "none";
            btnDeletes1._button.style.display = "none";
        } else {
            btnNews1._button.style.display = "";
            btnDeletes1._button.style.display = "";
        }
    });
} ();
YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(function () {
    var handleSubmit = function () {
        var editwindow = document.getElementById("EditUIWindow1");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
            loadData();
        }
        YAHOO.example.container.dialog1.hide();
    };
    var handleCancel = function () {
        this.cancel();
    };
    var handleSubmit2 = function () {
        var editwindow = document.getElementById("EditUIWindow2");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
        }
        YAHOO.example.container.dialog2.hide();
    };
    var handleSubmit3 = function () {
        var editwindow = document.getElementById("EditUIWindow3");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
        }
        YAHOO.example.container.dialog3.hide();
    };
    var handleSuccess = function (o) {
        var response = o.responseText;
        response = response.split("<!")[0];
        document.getElementById("resp").innerHTML = response;
    };
    var handleFailure = function (o) {
        alert("Submission failed: " + o.status);
    };
    YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", {
        width: "650px",
        height: "480px",
        fixedcenter: true,
        visible: false,
        draggable: true,
        close: true,
        autofillheight: "body",
        constraintoviewport: true,
        buttons: [{ text: "确定", handler: handleSubmit, isDefault: true },
			    { text: "取消", handler: handleCancel}]
    });
    YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2", {
        width: "360px",
        height: "450px",
        fixedcenter: true,
        visible: false,
        draggable: true,
        close: true,
        autofillheight: "body",
        constraintoviewport: true,
        buttons: [{ text: "确定", handler: handleSubmit2, isDefault: true },
			    { text: "取消", handler: handleCancel}]
    });
    YAHOO.example.container.dialog3 = new YAHOO.widget.Dialog("dialog3", {
        width: "520px",
        height: "450px",
        fixedcenter: true,
        visible: false,
        draggable: true,
        close: true,
        autofillheight: "body",
        constraintoviewport: true,
        buttons: [{ text: "确定", handler: handleSubmit3, isDefault: true },
			    { text: "取消", handler: handleCancel}]
    });
    YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
    YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.callback = { success: handleSuccess, failure: handleFailure };
    YAHOO.example.container.dialog2.render();
    YAHOO.example.container.dialog3.callback = { success: handleSuccess, failure: handleFailure };
    YAHOO.example.container.dialog3.render();
    //拖动大小
    var resize = new YAHOO.util.Resize("dialog1", {
        handles: ["br"],
        autoRatio: false,
        minWidth: 650,
        minHeight: 450,
        status: false
    });
    resize.on("startResize", function (args) {
        if (this.cfg.getProperty("constraintoviewport")) {
            var D = YAHOO.util.Dom;
            var clientRegion = D.getClientRegion();
            var elRegion = D.getRegion(this.element);
            resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
        } else {
            resize.set("maxWidth", null);
            resize.set("maxHeight", null);
        }
    }, YAHOO.example.container.dialog1, true);
    resize.on("resize", function (args) {
        var panelHeight = args.height;
        this.cfg.setProperty("height", panelHeight + "px");
    }, YAHOO.example.container.dialog1, true);
});
YAHOO.util.Event.addListener(window, "load", function () {
    BindData();
    hideCol();
    if (flag == 2) { loadData(); }
    if (flag == 1) {
        LoadData1();
    }
});

//业绩归属选择对应的方法和ID
function ShowDialog2(fn, id) {
    _fn = fn;
    _id = id;
    YAHOO.example.container.dialog2.show();
}
/*客户选择对应的方法和ID*/
var _fn, _id;
function ShowDialog(fn, id, src) {
    _fn = fn;
    _id = id;
    document.getElementById("EditUIWindow1").src = src;
    YAHOO.example.container.dialog1.show();
}
//人员想选择对应的方法和ID

function ShowDialog3(fn, id) {
    _fn = fn;
    _id = id;
    YAHOO.example.container.dialog3.show();
}
var loadData = function () {
    var vid = $("#OrderCode").val();
    var vc = "ID='" + vid + "' and deptid='" + $("#DeptId").val() + "'";
    LoadCustomerData();
    YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=V_CrmPayByCid&customCondition=" + vc + "", //条件 
            {success: function (res) {
                try {
                    var str = res.responseText;
                    EmptyData = str;
                    SetFormValue2(str);
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
        });
}

//选择客户编码显示客户信息
var LoadCustomerData = function () {
    var vid = $("#OrderCode").val();
    var vCId = "ID='" + vid + "' and deptid='" + $("#DeptId").val() + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmPayByCid&customCondition=" + vCId + "", //条件 
            {success: function (res) {
                try {
                    var str = res.responseText;
                    var arr = [];
                    var obj = eval(str);
                    $("#txtCustomerCode").val(obj[0].Code);
                    $("#CustomerName").val(obj[0].CustomerName);
                    $("#CustomerType").val(obj[0].TypeName);
                    if (obj[0].AddUserName == obj[0].CustomerMgrName) {
                        $("#AddUserName").val("");
                    } else {
                        $("#AddUserName").val(obj[0].AddUserName);
                    }
                    $("#SaleadName").val(obj[0].SaleadviserName);
                    $("#LectorName").val(obj[0].LectorName);
                    $("#txtActionUser").val(obj[0].UName);
                    $("#hdnActionUser").val(obj[0].TeachID);
                    $("#txtDeptId").val(obj[0].Expr1);
                    $("#DeptId").val(obj[0].DeptID);
                    $("#CustomerMgr").val(obj[0].CustomerMgrName);

                    for (var i = 0; i < obj.length; i++) {
                        var entity = {};
                        entity.ID = obj[i].ID;
                        entity.Caption = obj[i].Caption;
                        arr.push(entity);
                    }
                    LoadData1();
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
        });
}

//加载数据
var LoadData1 = function () {
    var vid = $("#OrderCode").val();
    var vc = "CustomerId='" + vid + "'";
    if (flag == 0 || strBack == "unDone") {
        vc = "CustomerId='" + vid + "' and AccountReceivable>0 and stateid in(SELECT PhraseID FROM  dbo.DatPhraseDetail WHERE (ClassID =(SELECT  ClassID FROM          dbo.DatPhraseClass WHERE      (ClassValue = 'OrderStateID'))) AND (PhraseValue = '4' OR PhraseValue = '3'))";
    }
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmProductPay&customCondition=" + vc + "&order=code", //条件 
            {success: function (res) {
                try {
                    var str = res.responseText;
                    var arr = [];
                    var obj = eval(str);
                    for (var i = 0; i < obj.length; i++) {
                        var entity = {};
                        entity.ID = obj[i].ID;
                        entity.OrderID = obj[i].OrderID;
                        entity.Code = obj[i].Code;
                        entity.Caption = obj[i].Caption;
                        entity.ProductId = obj[i].ProductId;
                        entity.AccountReceivable = obj[i].AccountReceivable;
                        entity.ResignMoney = obj[i].ResignMoney;
                        entity.Packname = obj[i].Packname;
                        entity.ProductPackID = obj[i].ProductPackID;
                        entity.TotalMoney = obj[i].TotalMoney;
                        entity.PayMoney = obj[i].PayMoney;
                        //entity.InComeMoney = entity.AccountReceivable - entity.ResignMoney;
                        entity.Explain = obj[i].Explain;
                        arr.push(entity);
                    }
                    ListRecord = arr;
                    if (ListRecord[0].OrderID == undefined) {
                        alert("请先填订单");
                    }
                    hideCol();
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
        });
}

var vCell, vRecord, vColumn;
var format1 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [], tempData = "", strTemp = [], y = 0;
    var id = "id" + Math.random();
    if (flag == 1) {
        if (strBack == "unDone" || strDirect == "directPay") {
            str1.push("<select id='" + id + "' onchange='ChangeEvent3(this);' name='OrderID' style='width:100;'>");
        } else {
            str1.push("<select id='" + id + "' onchange='ChangeEvent3(this);' disabled='disabled' name='OrderID' style='width:100;'>");
        }
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent3(this);' name='OrderID' style='width:100;'>");
    } str1.push("<option value='00000000-0000-0000-0000-000000000000'> </option>");
    var clng = ListRecord.length;
    if (clng > 1) {
        for (var i = 0; i < clng - 1; i++) {
            if (ListRecord[i].Code != ListRecord[i + 1].Code) {
                strTemp[y] = ListRecord[i];
                y++;
            }
            if (i == clng - 2) {
                strTemp[y] = ListRecord[clng - 1];
            }
        }
        if (y == 0) {
            strTemp[y] = ListRecord[0];
        }
        for (var i = 0; i < strTemp.length; i++) {
            if (flag == 1 && strTemp[i].Code == sData) {
                str1.push("<option value='" + strTemp[i].OrderID + "' selected>" + strTemp[i].Code + "</option>");
            } else {
                str1.push("<option value='" + strTemp[i].OrderID + "'>" + strTemp[i].Code + "</option>");
            }
        }
    }
    if (clng == 1) {
        if (flag == 1) {
            str1.push("<option value='" + ListRecord[0].OrderID + "' selected>" + ListRecord[0].Code + "</option>");
        } else {
            str1.push("<option value='" + ListRecord[0].OrderID + "'>" + ListRecord[0].Code + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format2 = function (elCell, oRecord, oColumn, sData) {
    vCell = elCell; vRecord = oRecord; vColumn = oColumn;
    elCell.innerHTML = "";
    var str1 = [];
    var id = "id" + Math.random();
    if (flag == 1) {
        if (strBack == "unDone" || strDirect == "directPay") {
            str1.push("<select id='" + id + "' onchange='ChangeEvent2(this);' name='ProductId'  style='width:120%;'>");
        } else {
            str1.push("<select id='" + id + "' onchange='ChangeEvent2(this);' disabled='disabled' name='ProductId'  style='width:120%;'>");
        }
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent2(this);' name='ProductId' style='width:120%;'>");
    }
    str1.push("<option value='00000000-0000-0000-0000-000000000001'> </option>");
    if (sData == null || sData == "" || flag == 1) {
        arrTemp = ListRecord;
    }
    for (var i = 0; i < arrTemp.length - 1; i++) {
        if (arrTemp[i].Caption == arrTemp[i + 1].Caption) {
            if ((i + 2) == arrTemp.length) {
                if (flag == 1 && arrTemp[i].Caption == sData) {
                    if (arrTemp[i].Caption == "") { arrTemp[i].Caption = "场次费"; }
                    str1.push("<option value='" + arrTemp[i].ProductId + "' selected>" + arrTemp[i].Caption + "</option>");
                } else {
                    if (arrTemp[i].Caption == "") { arrTemp[i].Caption = "场次费"; }
                    str1.push("<option value='" + arrTemp[i].ProductId + "'>" + arrTemp[i].Caption + "</option>");
                }
            }
        } else {
            if (flag == 1 && arrTemp[i].Caption == sData) {
                if (arrTemp[i].Caption == "") { arrTemp[i].Caption = "场次费"; }
                str1.push("<option value='" + arrTemp[i].ProductId + "' selected>" + arrTemp[i].Caption + "</option>");
            } else {
                if (arrTemp[i].Caption == "") { arrTemp[i].Caption = "场次费"; }
                str1.push("<option value='" + arrTemp[i].ProductId + "'>" + arrTemp[i].Caption + "</option>");
            }
            if ((i + 2) == arrTemp.length) {
                if (flag == 1 && ListRecord[i + 1].Caption == sData) {
                    if (arrTemp[i + 1].Caption == "") { arrTemp[i + 1].Caption = "场次费"; }
                    str1.push("<option value='" + arrTemp[i + 1].ProductId + "' selected>" + arrTemp[i + 1].Caption + "</option>");
                } else {
                    if (arrTemp[i + 1].Caption == "") { arrTemp[i + 1].Caption = "场次费"; }
                    str1.push("<option value='" + arrTemp[i + 1].ProductId + "'>" + arrTemp[i + 1].Caption + "</option>");
                }
            }
        }
    }
    if (arrTemp.length == 1) {
        if (flag == 1 && arrTemp[0].Caption == sData) {
            if (arrTemp[0].Caption == "") { arrTemp[0].Caption = "场次费"; }
            str1.push("<option value='" + arrTemp[i].ProductId + "' selected>" + arrTemp[0].Caption + "</option>");
        } else {
            if (arrTemp[0].Caption == "") { arrTemp[0].Caption = "场次费"; }
            str1.push("<option value='" + arrTemp[0].ProductId + "'>" + arrTemp[0].Caption + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format3 = function (elCell, oRecord, oColumn, sData) {
    if (sData == null) {
        elCell.innerHTML = "<input type=\"text\" value=\"\" disabled='disabled' onchange='ChangeEvent1(this);' readonly='readonly' name='AccountReceivable' style='width:95%;'>";
    } else {
        elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" disabled='disabled' onchange='ChangeEvent1(this);' readonly='readonly' name='AccountReceivable' style='width:95%;'>";
    }
}
var format4 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='CustomerBank' style='width:200px;'>");
    //    str1.push("<option value='00000000-0000-0000-0000-000000000000'> </option>");

    for (var i = 0; i < ListAccount[0].length; i++) {
        if (flag == 1 && ListAccount[0][i].PhraseText == sData) {
            str1.push("<option value='" + ListAccount[0][i].PhraseText + "' selected>" + ListAccount[0][i].PhraseText + "</option>");
        } else {
            str1.push("<option value='" + ListAccount[0][i].PhraseText + "'>" + ListAccount[0][i].PhraseText + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format5 = function (elCell, oRecord, oColumn, sData) {
    if (sData == null || sData == "null" || sData == "") {
        elCell.innerHTML = "<input type=\"text\" value=\"\" name='CustomerAccount' disabled='disabled' onchange='ChangeEvent1(this);' style='width:200px;'>";
    } else {
        elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\"  disabled='disabled'  name='CustomerAccount' onchange='ChangeEvent1(this);' style='width:200px;'>";
    }
}
var format0 = function (elCell, oRecord, oColumn, sData) {
    if (sData == null || sData == "null" || sData == "") {
        elCell.innerHTML = "<input type=\"text\" value=\"0\" name='InComeMoney' disabled='disabled' onchange='ChangeEvent1(this);' style='width:95%;'>";
    } else {
        elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\"  disabled='disabled'  name='InComeMoney' onchange='ChangeEvent1(this);' style='width:95%;'>";
    }
}
var format6 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random(); if (flag == 1) {
        //if (strBack == "unDone" || strDirect == "directPay") {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='PayType' style='width:120%;'>");
        // }else{
        //str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' disabled='disabled' name='PayType' style='width:120%;'>");
        //}
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='PayType' style='width:120%;'>");
    } str1.push("<option value='00000000-0000-0000-0000-000000000000'> </option>");
    for (var i = 0; i < ListPayType[0].length; i++) {
        if (flag == 1 && ListPayType[0][i].PhraseID == sData) {
            str1.push("<option value='" + ListPayType[0][i].PhraseID + "' selected>" + ListPayType[0][i].PhraseText + "</option>");
        } else {
            str1.push("<option value='" + ListPayType[0][i].PhraseID + "'>" + ListPayType[0][i].PhraseText + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var formatPackName = function (elCell, oRecord, oColumn, sData) {
    if (sData == null) {
        elCell.innerHTML = "<input type=\"text\" value=\"\" disabled='disabled' name='Packname' style='width:95%; background: #e7eaf4;'>";
    } else {
        elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" disabled='disabled' name='Packname' style='width:95%; background: #e7eaf4;'>";
    }
}
var format7 = function (elCell, oRecord, oColumn, sData) {
    if (sData == null) {
        elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' disabled='disabled' readonly='readonly' name='ResignMoney' style='width:95%;'>";
    } else {
        elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);'disabled='disabled'  readonly='readonly' name='ResignMoney' style='width:95%;'>";
    }
}
var format8 = function (elCell, oRecord, oColumn, sData) {
    if (sData == null || sData == "null" || sData == "") {
        elCell.innerHTML = "<input type=\"text\" value=\"\" name='PayMoney' readonly='readonly' onchange='ChangeEvent1(this);' maxlength='10' style='width:95%;'>";
    } else {
        if (strBack == "unDone" || strDirect == "directPay") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" readonly='readonly' onchange='ChangeEvent1(this);' maxlength='10' name='PayMoney' style='width:95%;'>";
        } else {

            if (flag == 0) {
                elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" readonly='readonly' onchange='ChangeEvent1(this);' maxlength='10' name='PayMoney' style='width:95%;'>";
            } else {
                elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" readonly='readonly' disabled='disabled' onchange='ChangeEvent1(this);' maxlength='10' name='PayMoney' style='width:95%;'>";
            }
        }
    }
}
var format9 = function (elCell, oRecord, oColumn, sData) {
    if (sData == null || sData == "null" || sData == "") {
        elCell.innerHTML = "<input type=\"text\" value=\"\" name='Explain' maxlength='50' onchange='ChangeEvent1(this);' style='width:95%;'>";
    } else {
        if (strBack == "unDone" || strDirect == "directPay") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" name='Explain' maxlength='50' onchange='ChangeEvent1(this);' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" name='Explain' maxlength='50'  disabled='disabled' onchange='ChangeEvent1(this);' style='width:95%;'>";
        }
    }
}
var format11 = function (elCell, oRecord, oColumn, sData) {
    elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" disabled='disabled' name='ProductName' style='width:95%; background: #e7eaf4;'>";
}
var format12 = function (elCell, oRecord, oColumn, sData) {
    elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" disabled='disabled' name='PayTypes' style='width:95%; background: #e7eaf4;'>";
}
var responseSuccess = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            window.location.href = "../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + getTsid;
        }
        else {
            alert(str);
        }
    } catch (e) {
    }
    finally {
    }
};
var responseSuccess1 = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert("数据保存成功"); Close1();
        }
        else {
            alert(str);
        }
    } catch (e) {
    }
    finally {
    }
}
var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};
var callback1 = {
    success: responseSuccess1,
    failure: responseFailure
};
//刷新父窗体数据
function RefreshDataParent() {
    if (parent.NeedRefreshPage != null) {
        if (typeof (parent.NeedRefreshPage.LoadData) == "function") {
            parent.NeedRefreshPage.RefreshData();
        }
    }
}

//值改变事件
var ChangeEvent1 = function (oArgs) {
    var f = oArgs.name;
    var v = oArgs.value;
    setValue1(f, v);
}
var ChangeEvent3 = function (oArgs) {
    var f = oArgs.name;
    var v = oArgs.value;
    setValue3(f, v);
}
var ChangeEvent2 = function (oArgs) {
    var f = oArgs.name;
    var v = oArgs.value;
    setValue2(f, v);
}
//f=字段名 v=值
var setValue1 = function (f, v) {

    var recordID = mDataTable1.getSelectedRows()[0];
    var record = mDataTable1.getRecord(recordID);
    record._oData[f] = v;
    var list = mDataTable1.getRecordSet()._records;
    if (f == "PayMoney") {
        if (isNaN(v)) {
            alert("本次金额必须输入数字!");
            //$($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=PayMoney]")[0]).val("");
            $($($(".yui-dt-selected")[0]).find("input[name=PayMoney]")[0]).val("");
            record._oData["PayMoney"] = "";
        }
        var cValue = 0;
        var tempsv = 0;
        var unPay = parseFloat($($($(".yui-dt-selected")[0]).find("input[name=InComeMoney]")[0]).val());
        var vs = parseFloat($($($(".yui-dt-selected")[0]).find("input[name=PayMoney]")[0]).val());
        //var unPay = parseFloat($($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val());
        //var vs = parseFloat($($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=PayMoney]")[0]).val());
        for (var i = 0; i < list.length; i++) {
            if (list[i]._oData.PayMoney != "") {
                //var v = parseFloat(list[i]._oData.PayMoney);

                if (!isNaN(unPay)) {
                    if (unPay <= 0) {
                        alert("该产品已缴完,不能缴款！");
                        $($($(".yui-dt-selected")[0]).find("input[name=PayMoney]")[0]).val("");
                        record._oData["PayMoney"] = "";
                        return;
                    }
                    if (vs > unPay && strBack != "unDone") {
                        unPay = vs + 1;
                        if (!confirm("本次金额大于待收金额，您确定没填错吗？")) {
                            //$($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=PayMoney]")[0]).val("");
                            $($($(".yui-dt-selected")[0]).find("input[name=PayMoney]")[0]).val("");
                            record._oData["PayMoney"] = "";
                            // v=0;
                            tempsv = 1;
                        }
                    }
                }
                //cValue = cValue + v;
            }
        }

        for (var i = 0; i < list.length; i++) {
            if (list[i]._oData.PayMoney != "") {
                var vv = parseFloat(list[i]._oData.PayMoney);
                if (isNaN(v)) {
                    vv = 0;
                }
                // cValue = parseFloat(cValue).toFixed(2);
                cValue += vv;
            }
        }

        cValue = parseFloat(cValue).toFixed(2);
        $('#AccountReceivable').val(cValue);
        $("#TotalMoney").val(cValue);

    }
    if (f == "CustomerBank") {
        for (var i = 0; i < ListAccount[0].length; i++) {
            if (ListAccount[0][i].PhraseText == v) {
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=CustomerAccount]")[0]).val(ListAccount[0][i].PhraseValue);
                record._oData["CustomerAccount"] = ListAccount[0][i].PhraseValue;
            }
        }
    }
}
var arrTemp = [];
var rm = 0;
var setValue3 = function (f, v) {
    var recordID = mDataTable1.getSelectedRows()[0];
    var record = mDataTable1.getRecord(recordID);
    record._oData[f] = v;
    var arr = [];
    var obj = ListRecord;
    var nums = 0;
    for (var i = 0; i < obj.length; i++) {
        if (ListRecord[i].OrderID == v) {
            rm = 1;
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Packname]")[0]).val(obj[i].Packname);
            record._oData["Packname"] = obj[i].Packname;
            if (obj[i].Packname != "") {
                setValue2("ProductId", obj[i].ProductPackID);
            } else {
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=AccountReceivable]")[0]).val("");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ResignMoney]")[0]).val("");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val("");
            }
        }
    }
    for (var i = 0; i < obj.length; i++) {
        if (ListRecord[i].OrderID == v) {
            var entity = {};
            if (obj[i].Caption == "") { nums++ }
            entity.Caption = obj[i].Caption;
            entity.ProductId = obj[i].ProductId;
            if (nums == 0) {
                arr.push(entity);
            }
        }
    }
    arrTemp = arr;
    format2(vCell, vRecord, vColumn, arrTemp);
    //mDataTable1.showColumn(parseInt(2));
}
var setValue2 = function (f, v) {

    var recordID = mDataTable1.getSelectedRows()[0];
    var record = mDataTable1.getRecord(recordID);
    record._oData[f] = v;
    if (rm == 1) {
        for (var i = 0; i < ListRecord.length; i++) {
            if (ListRecord[i].ProductId == v && record._oData["OrderID"] == ListRecord[i].OrderID) {
                rm = 0;
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=AccountReceivable]")[0]).val(ListRecord[i].AccountReceivable);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ResignMoney]")[0]).val(ListRecord[i].ResignMoney);
                if (ListRecord[i].AccountReceivable - ListRecord[i].ResignMoney > 0)
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(ListRecord[i].AccountReceivable - ListRecord[i].ResignMoney);
                else
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(0);
            }
        }
        if (rm > 0) {
            rm = 0;
            for (var i = 0; i < ListRecord.length; i++) {
                if (v == "00000000-0000-0000-0000-000000000001" && record._oData["OrderID"] == ListRecord[i].OrderID) {
                    if (ListRecord[i].ResignMoney != "") {
                        rm = parseFloat(rm) + parseFloat(ListRecord[i].ResignMoney);
                    }
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=AccountReceivable]")[0]).val(ListRecord[i].TotalMoney);
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ResignMoney]")[0]).val(rm);
                    if (ListRecord[i].TotalMoney - rm > 0) {
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(ListRecord[i].TotalMoney - rm);
                    }
                    else {
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(0);
                    }
                } else {
                    if (ListRecord[i].ProductPackID != "" && ListRecord[i].ProductPackID != "00000000-0000-0000-0000-000000000001" && record._oData["OrderID"] == ListRecord[i].OrderID && ListRecord[i].ProductPackID == v) {
                        if (ListRecord[i].ResignMoney != "") {
                            rm = parseFloat(rm) + parseFloat(ListRecord[i].ResignMoney);
                        }
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=AccountReceivable]")[0]).val(ListRecord[i].TotalMoney);
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ResignMoney]")[0]).val(rm);
                        if (ListRecord[i].TotalMoney - rm > 0) {
                            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(ListRecord[i].TotalMoney - rm);
                        }
                        else {
                            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(0);
                        }
                    }
                }
            }
        } rm = 1;
    } else {
        for (var i = 0; i < ListRecord.length; i++) {
            if (v == "00000000-0000-0000-0000-000000000001" && record._oData["Packname"] != "" && record._oData["OrderID"] == ListRecord[i].OrderID && record._oData["OrderID"] == ListRecord[i].OrderID) {
                if (ListRecord[i].ResignMoney != "") {
                    rm = parseFloat(rm) + parseFloat(ListRecord[i].ResignMoney);
                }
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=AccountReceivable]")[0]).val(ListRecord[i].TotalMoney);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ResignMoney]")[0]).val(rm);
                if (ListRecord[i].TotalMoney - rm > 0)
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(ListRecord[i].TotalMoney - rm);
                else {
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(0);
                }
                break;
            } else {
                if (record._oData["Packname"] != "" && v == "00000000-0000-0000-0000-000000000001" && record._oData["OrderID"] == ListRecord[i].OrderID && ListRecord[i].ProductPackID == v) {
                    if (ListRecord[i].ResignMoney != "") {
                        rm = parseFloat(rm) + parseFloat(ListRecord[i].ResignMoney);
                    }
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=AccountReceivable]")[0]).val(ListRecord[i].TotalMoney);
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ResignMoney]")[0]).val(rm);
                    if (ListRecord[i].TotalMoney - rm > 0)
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(ListRecord[i].TotalMoney - rm);
                    else {
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(0);
                    }
                    break;
                } else {
                    if (ListRecord[i].ProductId == v && record._oData["OrderID"] == ListRecord[i].OrderID) {
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=AccountReceivable]")[0]).val(ListRecord[i].AccountReceivable);
                        $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ResignMoney]")[0]).val(ListRecord[i].ResignMoney);
                        if (ListRecord[i].AccountReceivable - ListRecord[i].ResignMoney > 0)
                            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(ListRecord[i].AccountReceivable - ListRecord[i].ResignMoney);
                        else {
                            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=InComeMoney]")[0]).val(0);
                        }
                    }
                }
            }
        }
    }
    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=PayMoney]")[0]).val("");
    record._oData["PayMoney"] = "";
    LoadAccountReceivable();
}

var BindData = function () {
    YAHOO.example.InlineCellEditing = function () {
        var myColumnDefs1 = [
                { key: "OrderID", label: "ID", resizeable: true },
                { key: "Code", label: "订单编号", resizeable: true, formatter: format1 },
                { key: "Packname", label: "产品包名称", resizeable: true, width: 120, formatter: formatPackName },
                { key: "Caption", label: "产品名称", resizeable: true, formatter: format2 },
                { key: "AccountReceivable", label: "应收金额", resizeable: true, formatter: format3 },
                { key: "ResignMoney", label: "已收金额", resizeable: true, formatter: format7 },
                { key: "InComeMoney", label: "待收金额", resizeable: true, formatter: format0 },
                { key: "PayType", label: "付款方式", resizeable: true, formatter: format6 },
                { key: "CustomerBank", label: "到账银行", resizeable: true, formatter: format4 },
                { key: "CustomerAccount", label: "到账银行账号", resizeable: true, formatter: format5 },
                { key: "PayMoney", label: "本次金额", resizeable: true, formatter: format8,
                    editor: new YAHOO.widget.TextboxCellEditor({ validator: YAHOO.widget.DataTable.validateNumber })
                },
                { key: "Explain", label: "备注", resizeable: true, formatter: format9 },
                { key: "ProductId", label: "productID", resizeable: true },
                { key: "ProductName", label: "产品名称", resizeable: true, formatter: format11 },
                { key: "PayTypes", label: "付款方式", resizeable: true, formatter: format12 }
                ];
        myDataSource1 = new YAHOO.util.DataSource([{ OrderID: "", Code: "", Packname: "", ProductId: "", Caption: "", AccountReceivable: "", ResignMoney: "", InComeMoney: "", PayType: "", CustomerBank: "", CustomerAccount: "", PayMoney: "", Explain: "", ID: "", ProductName: "", PayTypes: ""
        }]);
        myDataSource1.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource1.responseSchema = {
            fields: ["OrderID", "Code", "Packname", "ProductId", "Caption", "AccountReceivable",
                         "ResignMoney", "InComeMoney", "PayType", "CustomerBank", "CustomerAccount", "PayMoney", "Explain", "ID", "ProductName", "PayTypes"]
        };
        var myDataTable1 = new YAHOO.widget.ScrollingDataTable("con_1",
                myColumnDefs1, myDataSource1, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable1 = myDataTable1;
        var i1 = 1,
                bReverseSorted1 = false;
        var trackReverseSorts1 = function (oArg) {
            bReverseSorted1 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        var onEventSaveCellEditor = function (oArgs) {
            setValue1(oArgs.editor._oColumn.key, oArgs.newData);
        }
        myDataTable1.subscribe("rowMouseoverEvent", myDataTable1.onEventHighlightRow);
        myDataTable1.subscribe("rowMouseoutEvent", myDataTable1.onEventUnhighlightRow);
        myDataTable1.subscribe("rowClickEvent", myDataTable1.onEventSelectRow);
        myDataTable1.subscribe("cellClickEvent", myDataTable1.onEventShowCellEditor);
        myDataTable1.subscribe("editorSaveEvent", onEventSaveCellEditor);
        myDataTable1.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue2();
        return {
            ds: myDataSource1,
            dt: myDataTable1
        };
    } ();
}
//隐藏/栏位
function hideCol() {
    mDataTable1.hideColumn(parseInt(0));
    mDataTable1.hideColumn(parseInt(14));
    if (flag == 0) {
        //mDataTable1.hideColumn(parseInt(2));
    }
    mDataTable1.hideColumn(parseInt(12));
    mDataTable1.hideColumn(parseInt(13));
    mDataTable1.refreshView();
}
var GetFormValue2 = function () {
    for (var i = 0; i < ListCrmProduct.length; i++) {
        SetFormValue2(ListCrmProduct);
    }
}
var SetFormValue2 = function (obj) {
    var arr = eval(obj);
    var totalMoney = 0;
    for (var i = 0; i < arr.length; i++) {
        totalMoney += parseFloat(arr[i].PayMoney);
        arr[i].InComeMoney = arr[i].AccountReceivable - arr[i].ResignMoney;
        if (isNaN(arr[i].InComeMoney)) {
            arr[i].InComeMoney = 0;
        }
    }
    if (!isNaN(totalMoney)) {
        totalMoney = parseFloat(totalMoney).toFixed(2);
        $("#TotalMoney").val(totalMoney);
    }
    myDataSource1.liveData = arr;
    mDataTable1.getDataSource().sendRequest(null, { success: mDataTable1.onDataReturnInitializeTable }, mDataTable1);
}
//新增行
var handleAdd = function () {
    mDataTable1.set("sortedBy", null);
    index = mDataTable1.getRecordSet()._records.length;
    var entity = [{ OrderID: "", Code: "", Packname: "", ProductId: "", Caption: "", AccountReceivable: "", ResignMoney: "", InComeMoney: "", PayType: "", CustomerBank: "", CustomerAccount: "", PayMoney: "", Explain: "", ID: ""
    }];
    if (mDataTable1.getRecordSet()._records[index - 1]._oData.ProductId == "" || mDataTable1.getRecordSet()._records[index - 1]._oData.ProductId == null) {
        alert("请选择第 " + index + " 行的订单编号和产品名称");
    } else {
        mDataTable1.addRows(entity, index);
    }
}
function LoadAccountReceivable() {
    var list = mDataTable1.getRecordSet()._records;
    var cValue = 0;
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData.PayMoney != "") {
            var v = parseFloat(list[i]._oData.PayMoney);
            if (isNaN(v)) {
                v = 0;
            }
            //cValue = parseFloat(cValue).toFixed(2);
            cValue += v;
        }
    }
    cValue = parseFloat(cValue).toFixed(2);

    $('#TotalMoney').val(cValue);
}
//删除行
var handleDelete = function () {
    var recordID = mDataTable1.getSelectedRows()[0];
    index = mDataTable1.getRecordSet()._records.length;
    if (recordID != null && recordID.length != 1) {
        if (mDataTable1.getRecordSet()._records.length == 1) {
            alert("最后一行不能删除");
            return;
        };

        mDataTable1.deleteRow(recordID);
        LoadAccountReceivable();

    } else {
        alert("请选中一行后删除！");
    }
}
//取值
function setValue() {
    instance[0].ID = $('#ID').val();
    instance[0].Code = $('#Code').val();
    instance[0].CustomerId = $('#OrderCode').val();
    instance[0].ValutaID = $('#ValutaID').val();
    instance[0].DeptId = $('#DeptId').val();
    instance[0].PillID = $('#PillID').val();
    instance[0].InvoiceNum = $('#InvoiceNum').val();
    instance[0].State = $('#State').val();
    instance[0].Date = $('#Date').val();
    instance[0].PayDate = $('#PayDate').val();
    instance[0].Explain = $('#Explain').val();
    instance[0].WorkTaskId = $('#WorkTaskId').val();
    instance[0].WorkFlowId = $('#WorkFlowId').val();
    instance[0].WorkFlowInsId = $('#WorkFlowInsId').val();
    instance[0].WorkTaskInsId = $('#WorkTaskInsId').val();
    instance[0].CheckUser = $('#CustomId').val();
    //instance[0].IsHeadquarter = $('#drpHQ').val();
    instance[0].EXP1 = $('#IsPerformance').val();
    if (strHistory != "") {
        instance[0].EXP3 = $('#txtActionUser').val();
        instance[0].EXP2 = $('#hdnActionUser').val();
        instance[0].EXP4 = "1@3";
    }
}
//取值
function setValueS() {
    instance1[0].ID = $('#ID').val();
    instance1[0].ValutaID = $('#ValutaID').val();
    instance1[0].DeptId = $('#DeptId').val();
    instance1[0].PayDate = $('#PayDate').val();
    instance1[0].PillID = $('#PillID').val();
    instance1[0].InvoiceNum = $('#InvoiceNum').val();
    instance1[0].State = $('#State').val();
    instance1[0].Explain = $('#Explain').val();
}
var trySave = function () {
    var formObject = document.getElementById('form2');
    YAHOO.util.Connect.setForm(formObject);
    var cObj = YAHOO.util.Connect.asyncRequest('POST', Url + "?flag=1&cName=" + encodeURI($("#CustomerName").val()) + "&action=" + action + "&entity=CrmPay", callback);
}
var trySaveDirect = function () {
    var formObject = document.getElementById('form2');
    YAHOO.util.Connect.setForm(formObject);
    var cObj = YAHOO.util.Connect.asyncRequest('POST', Url + "?flag=1&saveType=direct&action=" + action + "&entity=CrmPay", callback1);
}
function RefreshData() {
    alert('添加成功!可用继续添加');
    window.location.reload();
}
//是否价值业绩值改变事件
$('#IsPerformance').change(function () {
    //        var OptionValue = $(this).children('option:selected').val();
    //        if (OptionValue == "0") {
    //            document.getElementById("btnCustomId").style.display = "";
    //            $("#txtCustomId").val("");
    //        } else {
    //            document.getElementById("btnCustomId").style.display = "none";
    //            $("#txtCustomId").val("田文珊");
    //            $("#CustomId").val("E07D3D59-CF06-4C96-A653-7D9DCF8C191F");
    //        }
});
//保存产品数据
var cTemp = 0;
var SaveAgain = function () {
    if (cTemp == 1) {
        RefreshData();
    }
    cTemp++;
}
var Save = function () {
    if (flag == 0 || flag == 2 || flag == 1) {
        setValue();
        if (instance[0].CustomerId == null || instance[0].CustomerId == "") {
            alert("客户编码不能为空!");
            $('#OrderCode').focus();
            return;
        }
        if (instance[0].DeptId == null || instance[0].DeptId == "") {
            alert("业绩归属不能为空!");
            $('#DeptId').focus();
            return;
        }
        //        if (instance[0].PayType == null || instance[0].PayType == "") {
        //            alert("缴款单类型不能为空!");
        //            $('#PayType').focus();
        //            return;
        //        }
        if (instance[0].ValutaID == null || instance[0].ValutaID == "") {
            alert("币别不能为空!");
            $('#ValutaID').focus();
            return;
        }
        if (instance[0].PillID == null || instance[0].PillID == "") {
            instance[0].PillID = "00000000-0000-0000-0000-000000000000";
        }
        if (strDirect == "directPay") {
            if ($('#FactPayDate').val() == "") {
                alert("实际到款日期必须输入");
                $('#FactPayDate').focus();
                return;
            }
            //            if ($('#Receipt').val() == "") {
            //                alert("收据号必须输入");
            //                $('#Receipt').focus();
            //                return ;
            //            }
            instance[0].FactPayDate = $('#FactPayDate').val();
            instance[0].Receipt = $('#Receipt').val();
            instance[0].InvoiceNum = $('#InvoiceNum').val();
        }
        if ((instance[0].PayDate == null || instance[0].PayDate == "") && strDirect != "directPay") {
                        alert("预计时间不能为空!");
                        $('#PayDate').focus();
                        return;
            //instance[0].PayDate = "1900-01-01";
        }
        if ($("#PayDate").val() == "") {
            instance[0].PayDate = "1900-01-01";
        }
        if ($("#IsPerformance").val() == "") {
            alert("请选择价值业绩选项");
            $("#IsPerformance").focus();
            return;
        }
        if ((instance[0].CheckUser == null || instance[0].CheckUser == "") && strDirect != "directPay") {
            alert("请选择核算员!");
            $('#txtCustomId').focus();
            return;
        }
        var list = mDataTable1.getRecordSet()._records;
        var elist = [];
        instance[0].ProduectList = "";
        for (var i = 0; i < list.length; i++) {
            if (list[i]._oData.OrderID == null || list[i]._oData.OrderID == "00" || list[i]._oData.OrderID == "") {
                alert("第" + (i + 1) + "行 订单编码不能为空!");
                return;
            }
            if (strBack == "unDone") {
                if ((list[i]._oData.ProductId == null || list[i]._oData.ProductId == "00" || list[i]._oData.ProductId == "") && list[i]._oData.Packname == "") {
                    alert("第" + (i + 1) + "行 产品名称不能为空!");
                    return;
                }
                if (list[i]._oData.PayType == null || list[i]._oData.PayType == "00" || list[i]._oData.PayType == "") {
                    alert("第" + (i + 1) + "行 付款方式不能为空!");
                    return;
                }
            } else if (strDirect == "directPay" && flag == 1) {
                if ((list[i]._oData.ProductId == null || list[i]._oData.ProductId == "00" || list[i]._oData.ProductId == "") && list[i]._oData.Packname == "") {
                    alert("第" + (i + 1) + "行 产品名称不能为空!");
                    return;
                }
                if (list[i]._oData.PayType == null || list[i]._oData.PayType == "00" || list[i]._oData.PayType == "") {
                    alert("第" + (i + 1) + "行 付款方式不能为空!");
                    return;
                }
            }
            else {
                if ((list[i]._oData.ProductId == null || list[i]._oData.ProductId == undefined || list[i]._oData.ProductId == "00000000-0000-0000-0000-000000000001" || list[i]._oData.ProductId == "") && list[i]._oData.Packname == "") {
                    alert("第" + (i + 1) + "行 产品名称不能为空!");
                    return;
                }
                if (list[i]._oData.PayType == null || list[i]._oData.PayType == "00" || list[i]._oData.PayType == "") {
                    alert("第" + (i + 1) + "行 付款方式不能为空!");
                    return;
                }
            }
            //            if (strDirect == "directPay") {
            //                if (list[i]._oData.CustomerBank == null || list[i]._oData.CustomerBank == "null" || list[i]._oData.CustomerBank == "") {
            //                    alert("第" + (i + 1) + "行 收款开户银行不能为空!");
            //                    return;
            //                }
            //                if (list[i]._oData.CustomerAccount == null || list[i]._oData.CustomerAccount == "null" || list[i]._oData.CustomerAccount == "") {
            //                    alert("第" + (i + 1) + "行 收款银行账号不能为空!");
            //                    return;
            //                }
            //            }
            if (list[i]._oData.PayMoney == null || list[i]._oData.PayMoney == "" || parseInt(list[i]._oData.PayMoney) <= 0) {
                alert("第" + (i + 1) + "行 本次金额无效,且必须为大于0的数字!");
                return;
            }
            var tempValue = 0;
            var payMoney = list[i]._oData.PayMoney;
            //            for (var j = 0; j < ListRecord.length; j++) {
            //                if (ListRecord[j].ProductId == list[i]._oData.ProductId) {
            //                    tempValue = ListRecord[j].AccountReceivable;
            //                    //break;
            //                }
            //            } 
            //            if (parseInt(tempValue)!=0&&parseInt(payMoney)> parseInt(tempValue)) {
            //                alert("第" + (i + 1) + "行 缴款金额不能大于应收金额!");
            //                return;
            //            }
            elist.push(list[i]._oData);
        }
        for (var j = 0; j < elist.length; j++) {
            if (strBack == "unDone") {
                instance[0].ProduectList += "@" + elist[j].OrderID + "︾" + elist[j].ProductId + "︾" +
                                           elist[j].CustomerBank + "︾" + elist[j].CustomerAccount + "︾" + elist[j].PayMoney + "︾" + elist[j].PayType + "︾" + elist[j].Explain + "︾";

            } else if (strDirect == "directPay" && flag == 1) {
                instance[0].ProduectList += "@" + elist[j].ID + "︾" + elist[j].OrderID + "︾" + elist[j].ProductId + "︾" +
                                           elist[j].CustomerBank + "︾" + elist[j].CustomerAccount + "︾" + elist[j].PayMoney + "︾" + elist[j].PayType + "︾" + elist[j].Explain + "︾";
            }
            else {
                instance[0].ProduectList += "@" + elist[j].OrderID + "︾" + elist[j].ProductId + "︾" +
                                           elist[j].CustomerBank + "︾" + elist[j].CustomerAccount + "︾" + elist[j].PayMoney + "︾" + elist[j].PayType + "︾" + elist[j].Explain + "︾";
            }
        }
        var json = $.toJSON(instance[0]).replace(/'/g, "[B]"); ;
        $("#jsonDataContent").val(json);

        setTimeout(function () {
            var btn = document.getElementById("btnSave");
            if (btn != null)
                btn.disabled = true;

            var btnQ = document.getElementById("btnQdnx");
            if (btnQ != null) {
                btnQ.disabled = true;
            }
            if (strDirect == "directPay") {
                trySaveDirect();
            } else {
                trySave();
            }
            setTimeout(function () { if (btn != null) btn.disabled = false; if (btnQ != null) btnQ.disabled = false; }, 10000);
        }, 10);

        RefreshDataParent();
        Close();
    }
}
$(document).ready(function () {
    $('#PayDate').cld();
    $('#FactPayDate').cld();
    $('#Date').cld();
    $("#hdnSelectValue").val($("#IsPerformance").val());
    if ($("#FactPayDate").val() == "0001-01-01") {
        $("#FactPayDate").val("");
    }
});
//提交验正
var checkDate = function () {
    //获得 单选选按钮name集合 
    var radios = document.getElementsByName("1");
    $("#hdnMessage").val($("#tbxMessage").val());
    //根据 name集合长度 遍历name集合 
    for (var i = 0; i < radios.length; i++) {
        //判断那个单选按钮为选中状态 
        if (radios[i].checked && radios[i].value == "rbtNo") {
            //弹出选中单选按钮的值 
            $("#pCheck").val("no");
            return true;
        }
    }
    /*if ($('#InvoiceNum').val() == "") {
    alert("发票号必须输入");
    $('#InvoiceNum').focus();
    return false;
    }
    if ($('#Receipt').val() == "") {
    alert("收据号必须输入");
    $('#Receipt').focus();
    return false;
    }*/
    if ($('#FactPayDate').val() == "") {
        alert("实际到款日期必须输入");
        $('#FactPayDate').focus();
        return false;
    }
    var pList = mDataTable1.getRecordSet()._records;
    var pValue = "";
    for (var i = 0; i < pList.length; i++) {
        //        if (pList[i]._oData.CustomerBank == null || pList[i]._oData.CustomerBank == "null" || pList[i]._oData.CustomerBank == "") {
        //            alert("第" + (i + 1) + "行 收款开户银行不能为空!");
        //            return false;
        //        }
        //        if (pList[i]._oData.CustomerAccount == null || pList[i]._oData.CustomerAccount == "null" || pList[i]._oData.CustomerAccount == "") {
        //            alert("第" + (i + 1) + "行 收款银行账号不能为空!");
        //            return false;
        //        }
        pValue += "@" + pList[i]._oData.ID + "︾" + pList[i]._oData.CustomerAccount + "︾" + pList[i]._oData.CustomerBank + "︾" + pList[i]._oData.PayType + "︾";
    }
    $("#pValue").val(pValue);
    $("#pFactPayDate").val($("#FactPayDate").val());
    $("#pReceipt").val($("#Receipt").val());
    $("#pInvoiceNum").val($("#InvoiceNum").val());
    return true;
}